/**
 * Created by yaoxinhui on 2018/5/25.
 */

angular.module('gaUser').service("userInfoService", ["$q", "$http", "$cookies", "$location", function ($q, $http, $cookies, $location) {
  this.doLogin = function (params) {
    $http.post("http://localhost:8080/app/user/login", params).then(function(resp) { //无论是否保存成功，都进行页面跳转
//                    console.log("Saved Successfully! Status: " + JSON.stringify(resp.data.code));
      console.log("resp: " + angular.toJson(resp.data.code));
      var data = resp.data.data;
      var code = resp.data.code;
      if(code == 200){
        $cookies.put('token',data.token);
        $location.path("/offer/list");
      }else{
        alert("账号或密码不正确");
      }
    }, function(resp) {
      alert("账号或密码不正确");
    });
  }

  this.getUserKey = function () {
    var token = $cookies.get("token");
    if(token != null){
      return token;
    }else{
      return null;
    }
  }
}]);